package cc.vv.btpartyjob.partymanager.view

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import cc.vv.btpartyjob.jnimodule.server.OperationServer
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.moudel.bean.ProjectDetailJieDuanObj
import cc.vv.lkbasecomponent.util.LKScreenUtil
import java.util.*

/**
 * 项目详情进程
 * Created by  Chen.qi on 2018/10/24.
 */
class ProjectDetailProgessView : LinearLayout {
    /**
     * 上下文
     */
    private var mContext: Context? = null
    /**
     * 父布局
     */
    private var llSelectedAll: LinearLayout? = null


    constructor(context: Context) : this(context, null) {
        mContext = context
    }

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) {
        mContext = context
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        mContext = context
        val inflateView = View.inflate(context, R.layout.layout_operation_view, null)
        llSelectedAll = inflateView.findViewById(R.id.ll_lov_showAll)
        this.addView(inflateView)
    }


    /**
     * 填充选项数据
     *
     * @param optionList 数据集
     * @param itemSize   每行有几个选项
     */
    @SuppressLint("SetTextI18n")
    fun addAllSelectedFileView(optionList: ArrayList<ProjectDetailJieDuanObj>?, state: Int?) {
        if (null == optionList) {
            return
        }
        //清除
        clearAllJobOptionView()
        val viewWight = (LKScreenUtil.getScreenWidth() - LKScreenUtil.dp2px(52f))
        val layoutParams1 = LayoutParams(viewWight, LayoutParams.WRAP_CONTENT)
        for (i in 0 until optionList!!.size) {
            val view = LayoutInflater.from(mContext).inflate(R.layout.layout_project_course, null)
            view.layoutParams = layoutParams1
            view.setPadding(LKScreenUtil.dp2px(12f), 0, 0, 0)

            //阶段
            val tvJieduanTitle = view.findViewById<TextView>(R.id.tv_lpc_courseIntroNum)

            //申请延期
            val tvYanQiStatus = view.findViewById<TextView>(R.id.tv_lpc_courseStatus)

            //内容
            val tvContent = view.findViewById<TextView>(R.id.tv_lpc_projectContent)

            //预警时间
            val tvYuJingTime = view.findViewById<TextView>(R.id.tv_lpc_projectWarningTime)

            //预警描述
            val tvYuJingDesc = view.findViewById<TextView>(R.id.tv_lpc_projectWarningDesc)

            when (state) {
                0 -> {
                    //正常
                    tvYuJingDesc?.text = "(正常)"

                }
                1 -> {
                    //延期
                    tvYuJingDesc?.text = "(延期)"
                }
                2 -> {
                    // 预警
                    tvYuJingDesc?.text = "(预警)"
                }
                3 -> {
                    //取消
                    tvYuJingDesc?.text = "(取消)"
                }
                4 -> {
                    //结项
                    tvYuJingDesc?.text = "(结项)"
                }
            }

//            tvYanQiStatus.setOnClickListener({
//
//            })

            //预计完成时间
            val tvCompleteTime = view.findViewById<TextView>(R.id.tv_lpc_planCompleteDate)

            //项目状态
            val tvProjectState = view.findViewById<TextView>(R.id.tv_lpc_projectStatus)

            tvJieduanTitle?.text = "第${i + 1}阶段"
            val addProjectObj = optionList[i]
            tvContent?.text = addProjectObj.content
            tvYuJingTime?.text = OperationServer.formatStr(addProjectObj.warningTime)
            tvCompleteTime?.text = OperationServer.formatStr(addProjectObj.completeTime)
//            if (i == 0) {
//                tvYanQiStatus?.visibility = View.GONE
//            } else {
//                tvYanQiStatus?.visibility = View.GONE
//            }
            if (null != addProjectObj.state) {
                when (addProjectObj.state) {
                    0 -> {
                        tvProjectState?.text = "未开始"
                    }
                    1 -> {
                        tvProjectState?.text = "进行中"
                    }
                    2 -> {
                        tvProjectState?.text = "已完成"
                    }
                }
            }

            val tv = TextView(mContext)
            val layoutParamstv = LayoutParams(LKScreenUtil.dp2px(3f),LKScreenUtil.dp2px(8f))
            tv.layoutParams = layoutParamstv
            llSelectedAll?.addView(tv)
            llSelectedAll?.addView(view)
        }
    }

    /**
     * 清除view
     */
    private fun clearAllJobOptionView() {
        llSelectedAll?.removeAllViews()
    }

}